// Author: combacsa@kaist.ac.kr
// http://www.jungol.co.kr/prog/Hanal/hanalView.php?qs_code=1019

//#define COMPILE
// 가벼운 DP?
// 2000년 KOI 초등부 3번
#ifdef COMPILE

#include <fstream>
using namespace std;

int n;
int data[50001];
int sum[50001];
int dp[3][50001];
int m;

void input() {
	ifstream in("input.txt");

	in >> n;
	int tmp = 0;
	for (int i = 1; i <= n; i++) {
		in >> data[i];
	}
	in >> m;

	for (int j = 1; j <= m; j++) {
		sum[m] += data[j];
	}

	for (int k = m + 1; k <= n; k++) {
		sum[k] = sum[k - 1] - data[k - m] + data[k];
	}

	in.close();
}

void solve() {
	for (int i = m; i <= n; i++) {
		dp[0][i] = sum[i];
		if (dp[0][i] < dp[0][i-1])
			dp[0][i] = dp[0][i-1];
	}

	for (int j = 1; j < 3; j++) {
		for (int k = m * (j + 1); k <= n; k++) {
			dp[j][k] = dp[j-1][k-m] + sum[k];
			if (dp[j][k] < dp[j][k-1])
				dp[j][k] = dp[j][k-1];
		}
	}
}

void output() {
	ofstream out("output.txt");
	out << dp[2][n];
	out.close();
}

int main() {
	input();
	solve();
	output();

	return 0;
}
#endif
